package models

import (
	"github.com/goravel/framework/contracts/database/factory"
	"github.com/goravel/framework/database/orm"
	. "goravel/app/models/common"
	"goravel/database/factories"
)

type User struct {
	orm.Model
	Name          string     `gorm:"column:name;type:varchar(255);not null;default:''" form:"name" json:"name"`
	Mobile        string     `gorm:"column:mobile;type:varchar(255);not null;default:''" form:"mobile" json:"mobile"`
	Password      string     `gorm:"column:password;type:varchar(255);not null;default:''" form:"password" json:"password"`
	Area          string     `gorm:"column:area;type:varchar(255);not null;default:''" form:"area" json:"area"`
	Contact       string     `gorm:"column:contact;type:varchar(255);not null;default:''" form:"contact" json:"contact"`
	ContactMobile string     `gorm:"column:contact_mobile;type:varchar(255);not null;default:''" form:"contact_mobile" json:"contact_mobile"`
	Address       string     `gorm:"column:address;type:varchar(255);not null;default:''" form:"address" json:"address"`
	IdCard        string     `gorm:"column:id_card;type:varchar(255);not null;default:''" form:"id_card" json:"id_card"`
	ControlArr    ControlArr `gorm:"column:control_arr;type:varchar(255);null;default:''" form:"control_arr" json:"control_arr"`
	Pid           uint       `gorm:"column:pid;type:int(11);null;default:0" form:"pid" json:"pid"`
	IsAdmin       int        `gorm:"column:is_admin;comment:是否运营商" form:"is_admin" json:"is_admin"`
	Parent        *User      `gorm:"foreignKey:Pid;references:id" form:"parent" json:"parent"`
	Children      []User     `gorm:"foreignKey:Pid;references:id" form:"children" json:"children"`
	GrantArr      GrantArr   `gorm:"column:grant_arr;type:varchar(255);" form:"grant_arr" json:"grant_arr"`
	orm.SoftDeletes
}

func (*User) Factory() factory.Factory {
	return &factories.UserFactory{}
}

func (u *User) IsSuperAdmin() bool {
	return u.ID == 1
}
